<%@page import="com.liferay.portal.service.permission.PortletPermissionUtil"%>
<%@page import="com.liferay.portal.security.permission.ActionKeys"%>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ include file="/html/library/init.jsp" %>

Welcome to <h2><%= ParamUtil.getString(request, "company-name", "MindTree") %></h2> Library

<%-- 
<portlet:renderURL var="editBookURL">
	<portlet:param name="jspPage" value="/html/library/edit-book.jsp"/>
</portlet:renderURL>
--%>

<script language="javascript">
	function <portlet:namespace/>searchBook(frm){
		frm.<portlet:namespace/>searchType.value = "search";
		frm.submit();
	}
</script>

<%
	PortletURL editBookURL = renderResponse.createRenderURL();
	editBookURL.setParameter("jspPage", "/html/library/edit-book.jsp");
	
	PortletURL listBooksURL = renderResponse.createRenderURL();
	listBooksURL.setParameter("jspPage", "/html/library/list.jsp");
	
	PortletURL quickFindURL = renderResponse.createActionURL();
	quickFindURL.setParameter(ActionRequest.ACTION_NAME, "quickFind");
	
	System.out.println("portletName ==> " + portletName);
	
	boolean enableLink = 
		PortletPermissionUtil.contains(permissionChecker, plid.longValue(), "libraryportlet_WAR_libraryportlet", ActionKeys.ADD_ENTRY);
	
	System.out.println("enableLink == > " + enableLink);
%>

<aui:form method="POST" action="<%= quickFindURL.toString() %>">
	<aui:input type="hidden" name="searchType" />
	<aui:input name="bookTitle" label="Enter Book Title"/>
	<aui:button type="submit" value="Find" />
	<input type="button" value="Search" onClick="javascript:<portlet:namespace/>searchBook(this.form);"/>
</aui:form>

<br/>

<c:if test="<%= enableLink %>">
	<a href="<%= editBookURL.toString() %>">Add a book &raquo;</a>
</c:if>

&nbsp;<a href="<%= listBooksURL.toString() %>">Show List &raquo;</a>
